# Contributor: Rasmus Thomsen <oss@cogitri.dev>
# Contributor: Natanael Copa <ncopa@alpinelinux.org>
# Maintainer: Patrycja Rosa <alpine@ptrcnull.me>
pkgname=librsvg
pkgver=2.58.0
pkgrel=0
pkgdesc="SAX-based renderer for SVG files into a GdkPixbuf"
url="https://wiki.gnome.org/Projects/LibRsvg"
arch="all"
license="LGPL-2.1-or-later"
depends_dev="rsvg-convert=$pkgver-r$pkgrel"
makedepends="
	bzip2-dev
	cairo-dev
	cargo
	font-dejavu
	gi-docgen
	glib-dev
	gobject-introspection-dev
	gtk+3.0-dev
	libgsf-dev
	py3-docutils
	rust
	vala
	"
install="$pkgname.post-upgrade"
subpackages="
	$pkgname-dbg
	$pkgname-dev
	$pkgname-doc
	rsvg-convert:_convert
	rsvg-convert-doc:_convert_doc:noarch
	"
source="https://download.gnome.org/sources/librsvg/${pkgver%.*}/librsvg-$pkgver.tar.xz
	Cargo-update.patch
	"
# tests are very dependent on versions of pango/cairo/freetype
options="!check net"

# secfixes:
#   2.56.3-r0:
#     - CVE-2023-38633
#   2.50.4-r0:
#     - RUSTSEC-2020-0146
#   2.46.2-r0:
#     - CVE-2019-20446

export RUSTFLAGS="$RUSTFLAGS -C debuginfo=1"

prepare() {
	default_prepare
	git init -q

	# XXX: Hack to prevent rebuild on install.
	sed -Ei \
		-e 's/^(install-binSCRIPTS:) \$\(bin_SCRIPTS\)/\1/' \
		-e 's/^(install-am:) all-am/\1/' \
		Makefile.in
}

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--libexecdir=/usr/lib/$pkgname \
		--disable-static \
		--enable-vala
	make
}

check() {
	make check
}

package() {
	make DESTDIR="$pkgdir" install
}

_convert() {
	pkgdesc="CLI utility to convert SVG files to PNG format"

	amove usr/bin/rsvg-convert
}

_convert_doc() {
	pkgdesc="CLI utility to convert SVG files to PNG format (documentation)"
	depends=""
	install_if="docs ${subpkgname%-doc}=$pkgver-r$pkgrel"

	pkgdir="$pkgdir-doc" amove usr/share/man/man1/rsvg-convert.*
}

sha512sums="
56bf2b1b9b524142b4b79fe6f289cb33f334ab8a714f9898dacecc9461fbea8248477c29929446503e7a8d8cd16152ee3b7b7807279e436b6d079cfa6a4b1151  librsvg-2.58.0.tar.xz
1b82a29129cfcf424ecce9c479d48fb2de2aa65815cd55bac5184ec22845047b252deccdc2df23ab6a2aebc0cdcbccd6a1da10fe436e1177c8d03a04b2088345  Cargo-update.patch
"
